package com.xiaotu.dao;

import com.xiaotu.model.EnterpriseFileModel;
import com.xiaotu.model.ParamModel;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @作者 王艳龙
 * @日期 2021-01-29 15:06
 * @功能
 */
@Mapper
public interface FileDao {

    /**
     * 获取文件详细信息
     * @param param
     * @return
     */
    @Select("<script>"
            + "select * FROM tab_enterprise_file "
            + " where 1=1 "
            + "<if test='enterpriseId !=null and enterpriseId !=\"\" '>"
            + " and enterprise_id=${enterpriseId} "
            + "</if>"
            + "<if test='menuId !=null and menuId !=\"\" '>"
            + " and menu_id=${menuId} "
            + "</if>"
            + "<if test='applyId !=null and applyId !=\"\" '>"
            + " and apply_id=${applyId} "
            + "</if>"
            + "<if test='fileTabId !=null and fileTabId !=\"\" '>"
            + " and file_tab_id=${fileTabId} "
            + "</if>"
            + "<if test='fileTitleId !=null and fileTitleId !=\"\" '>"
            + " and file_title_id=${fileTitleId} "
            + "</if>"
            + " ORDER BY file_title_id "
            + "</script>")
    public List<EnterpriseFileModel> queryFileDetailInfo(ParamModel param);

    /**
     * 新增上传文件
     * @param fileModel
     */
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty ="fileModel.id")
    @Insert(" INSERT INTO "+EnterpriseFileModel.TABLE_NAME+" (file_name, file_type, suffix, size, length, store_path, "
            + " enterprise_id, menu_id,apply_id,file_tab_id,file_title_id, create_time) "
            + " VALUES (#{fileModel.fileName}, #{fileModel.fileType}, #{fileModel.suffix}, #{fileModel.size},"
            + " #{fileModel.length}, #{fileModel.storePath}, #{fileModel.enterpriseId}, #{fileModel.menuId},"
            + " #{fileModel.applyId}, #{fileModel.fileTabId},#{fileModel.fileTitleId},#{fileModel.createTime}) ")
    public void addFileInfo(@Param("fileModel") EnterpriseFileModel fileModel);


    /**
     * 根据id获取文件信息
     * @param fielId
     * @return
     */
    @Select(" select * from  "+EnterpriseFileModel.TABLE_NAME+" where id=#{fileId} ")
    public EnterpriseFileModel queryFileInfo(Integer fielId);

    /**
     * 根据id删除文件信息
     * @param fileId
     */
    @Delete(" delete from "+EnterpriseFileModel.TABLE_NAME+" where id=#{fileId} ")
    public void deleteFileInfo(Integer fileId);


    /**
     * 根据id获得企业用户基本信息
     * @param enterpriseId
     * @return
     */
    @Select(" select * from tab_enterprise_user where enterprise_id=#{enterpriseId} ")
    public Map<String,Object> queryEnterpriseInfo(String enterpriseId);


    /**
     * 修改企业基本信息营业照片
     * @param businessLicensePath
     * @param enterpriseId
     * @param fileName
     */
    @Update(" update tab_enterprise_user set business_license_path=#{businessLicensePath},business_license_name=#{fileName} WHERE enterprise_id=#{enterpriseId} ")
    public void updateEnterpriseInfo(@Param("businessLicensePath") String businessLicensePath,@Param("fileName") String fileName,@Param("enterpriseId") String enterpriseId);

}
